﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;

namespace Tesla.Util.UIUtilities
{
    [ToolboxData("<{0}:TeslaCheckbox runat=server></{0}:TeslaCheckbox>")]
    public class TeslaCheckbox:CheckBox
    {
        #region Variables
        
        //bool isDirty = false;
        
        #endregion

        #region CUSTOM PROPERTIES
        //public bool Dirty
        //{
        //    get
        //    {
        //        return ViewState["isDirty"] == null ? false : (bool)ViewState["IsDirty"];
        //        //return (bool)ViewState["IsDirty"];

        //    }
        //    set
        //    {
        //        ViewState["isDirty"] = value;
        //    }
        //}
        #endregion

        #region overridden methods

        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            writer.AddAttribute("_Dirty", "false");
        }
        protected override void OnPreRender(EventArgs e)
        {
            if (!Page.ClientScript.IsClientScriptBlockRegistered("ValidateDropdown"))
                Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Setting_Dirty", "function Setting_Dirty(ct1)" + "{document.getElementById(ct1).setAttribute(\"_Dirty\",\"true\");}", true);
            //base.OnPreRender(e);
        }
        protected override void Render(HtmlTextWriter writer)
        {
            this.Attributes.Add("onclick", "Setting_Dirty('" + this.ID + "')");
            base.Render(writer);
        }

        #endregion

    }
}
